/**
 * Simple regex experiment to create an automatic emoticons by Taufik Nurrohman and modified by aiizahhblog-team, and thanks to indo.mt5 & KASKUS for the smilies
 * Visit: http://aiizahh.blogspot.com
 * Update: 23 April 2013
 * Don't edit and publish this script without give credit as a thief
 */

$(function() {

	// Append an emoticon bar before comment-form
	if (putEmoAbove) {
		$(putEmoAbove).before('<div class="emoWrap"> dad deff depressed greedy dontcare order shake slap smoke spoiled support tired angry1 angry2 cheer cry4 drunk happy haii hmmm huhhh khekhe omg peace2 pleased wat2 winds kimpoi1 ngacirs angel1 bingungs ceweks fd1 hammers hotnewz jempol1 kimpoi2 marah1 najiss ngacir1 ngacir1 nosara rate5 maho ultahh lebaran</div>');
	}
	function emo(emo, imgRep, emoKey) {
		$(emoRange).each(function() {
			$(this).html($(this).html().replace(/<br ?\/?>(:|;|=|\^)/ig, "<br> $1").replace(emo, " <img src='" + imgRep + "' class='emo delayLoad' alt='" + emoKey + "' />"));
		});
	}
	emo(/\sdad/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/dad.gif", "dad");
	emo(/\sdeff/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/deff.gif", "deff");
	emo(/\sdepressed/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/depressed.gif", "depressed");
	emo(/\sgreedy/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/greedy.gif", "greedy");
	emo(/\sdontcare/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/idontcare.gif", "dontcare");
	emo(/\sorder/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/order.gif", "order");
	emo(/\sshake/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/shake.gif", "shake");
	emo(/\sslap/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/slap.gif", "slap");
	emo(/\ssmoke/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/smoke.gif", "smoke");
	emo(/\sspoiled/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/spoiled.gif", "spoiled");
	emo(/\ssupport/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/support.gif", "support");
	emo(/\stired/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/tired1.gif", "tired");
        emo(/\sangry1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/angry1.gif", "angry1");
	emo(/\sangry2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/angry2.gif", "angry2");
	emo(/\scheer/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/cheer.gif", "cheer");
	emo(/\scry4/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/cry4.gif", "cry4");
	emo(/\sdrunk/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/drunk.gif", "drunk");
	emo(/\shappy/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/happy.gif", "happy");
	emo(/\shaii/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/hi.gif", "haii");
	emo(/\shmmm/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/hmm.gif", "hmmm");
	emo(/\shuhhh/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/huhh.gif", "huhhh");
	emo(/\skhekhe/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/khekhe.gif", "khekhe");
	emo(/\somg/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/omg.gif", "omg");
	emo(/\speace2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/peace2.gif", "peace2");
        emo(/\spleased/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/pleased.gif", "pleased");
	emo(/\swat2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/wat2.gif", "wat2");
	emo(/\swinds/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/wind.gif", "winds");
	emo(/\skimpoi1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/1%20kimpoi.gif", "kimpoi1");
	emo(/\sngacirs/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/1%20ngacir.gif", "ngacirs");
	emo(/\sangel1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/angel1.gif", "angel1");
	emo(/\sbingungs/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/bingung.gif", "bingungs");
	emo(/\sceweks/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/cewek.gif", "ceweks");
	emo(/\sfd1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/fd_1.gif", "fd1");
	emo(/\shammers/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/hammer.gif", "hammers");
	emo(/\shotnewz/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/hotnews.gif", "hotnewz");
	emo(/\sjempol1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/jempol1.gif", "jempol1");
	emo(/\skimpoi2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/kimpoi.gif", "kimpoi2");
        emo(/\smarah1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/marah.gif", "marah1");
	emo(/\snajiss/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/najis.gif", "najiss");
	emo(/\sngacir1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/ngacir2.gif", "ngacir1");
	emo(/\sngacir2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/ngacir3.gif", "ngacir2");
	emo(/\snosara/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/nosara.gif", "nosara");
	emo(/\srate5/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/rate5.gif", "rate5");
	emo(/\smaho/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/s_sm_maho.gif.gif", "maho");
	emo(/\sultahh/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/ultah.gif", "ultahh");
	emo(/\slebaran/g, "http://aiizahh-reader.googlecode.com/svn/trunk/emot%20kaskus/lebaran03.gif", "lebaran");


	var one = 0; // Show alert one times!

	// Click anywhere to hide the emoticon
	$(document.body).on("click", function() {
		$('.emoKey').remove();
	});

	// Click to show the code!
	$('.emo').css('cursor', 'pointer').on("click", function(e) {
		$('.emoKey').remove();
		$(this).after('<input class="emoKey" type="text" size="5" value=" ' + this.alt + '" />');
		$('.emoKey').trigger("select");
		if(emoMessage && one === 0) {
			alert(emoMessage);
			one = 1;
		}
		e.stopPropagation();
	});

});
